package metier;

import java.sql.Date;

import javax.swing.JOptionPane;

/**
 * 
 * @author fbremand
 *
 */
public class Seance
{
	private int numSeance;
	private String jour;
	private Date dateSeance;
	private int nbPlacesAchetees;
	private Salle laSalle;
	private Film leFilm;
	private Horaire HoraireDebut;
	private Tarif leTarif;
	
	/**
	 * @param numSeance
	 * @param jour
	 * @param dateSeance
	 * @param nbPlacesAchetees
	 */
	public Seance(int numSeance, String jour, Date dateSeance,
			int nbPlacesAchetees, Salle uneSalle, Film unFilm, Horaire unHoraire, Tarif unTarif)
	{
		super();
		this.numSeance = numSeance;
		this.jour = jour;
		this.dateSeance = dateSeance;
		this.nbPlacesAchetees = nbPlacesAchetees;
		this.laSalle = uneSalle;
		this.leFilm = unFilm;
		this.HoraireDebut = unHoraire;
		this.leTarif = unTarif;
		this.leFilm.ajouterSeance(this);
	}
	
	public Seance(String jour, Date dateSeance,
			int nbPlacesAchetees, Salle uneSalle, Film unFilm, Horaire unHoraire, Tarif unTarif)
	{
		super();
		this.jour = jour;
		this.dateSeance =  dateSeance;
		this.nbPlacesAchetees = nbPlacesAchetees;
		this.laSalle = uneSalle;
		this.leFilm = unFilm;
		this.HoraireDebut = unHoraire;
		this.leTarif = unTarif;
		this.leFilm.ajouterSeance(this);
	}
	
	public String getJour()
	{
		return jour;
	}

	public void setJour(String jour)
	{
		this.jour = jour;
	}

	public Date getDateSeance()
	{
		return dateSeance;
	}

	public void setDateSeance(Date dateSeance)
	{
		this.dateSeance = dateSeance;
	}

	public int getNbPlacesAchetees()
	{
		return nbPlacesAchetees;
	}

	public void setNbPlacesAchetees(int nbPlacesAchetees)
	{
		this.nbPlacesAchetees = nbPlacesAchetees;
	}

	public Salle getLaSalle()
	{
		return laSalle;
	}

	public void setLaSalle(Salle laSalle)
	{
		this.laSalle = laSalle;
	}

	public Film getLeFilm()
	{
		return leFilm;
	}

	public void setLeFilm(Film leFilm)
	{
		this.leFilm = leFilm;
	}

	public Horaire getHoraireDebut()
	{
		return HoraireDebut;
	}

	public void setHoraireDebut(Horaire horaireDebut)
	{
		HoraireDebut = horaireDebut;
	}

	public Tarif getLeTarif()
	{
		return leTarif;
	}

	public void setLeTarif(Tarif leTarif)
	{
		this.leTarif = leTarif;
	}
	
	public int nbPlacesRestantes()
	{
		int res;

	    res = getLaSalle().getNbPlacesTotales() - this.nbPlacesAchetees;
	    
	    return res;
	}
    
	public boolean assezDePlace(int nb)
    {
		boolean res;

		res = false;
		if(nb <= nbPlacesRestantes())
		{
			res = true;
    	}
		else
		{
			JOptionPane.showMessageDialog(null, "Il n'y a plus de places restantes pour cette Séance");
		}
    	return res;
    }
	
	public String enChaine()
	{
		return ("La Seance " + this.numSeance + "du " + this.jour + " pour le film " + this.leFilm.enChaine() + " à partir de " + this.HoraireDebut.enChaine() + " au tarif " + this.leTarif.enChaine() + 
				" avec un nombre de places achetées égal à " + this.nbPlacesAchetees);
	}
}
